package com.jhwang;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

/**
 * 配置问价存储类
 * @Auther: jhwang
 * @Date: 2020/5/1 10:14
 * @Description:
 */
public  class GetPropertis {

    //配置文件路径
    public static String CONFIG_PATH =  System.getProperty("user.dir")+"\\src\\main\\config\\download.properties";

    //下载存储路径
    public static String DOWNLOAD_PATH = "D:\\dmsc\\download";

    //下载url路径
    public static String[] DOWNLOAD_URL;

    //下载模式
    public static String DOWNLOAD_MODEL = "0" ;


    static {
        Properties properties;
        try {
            Properties configProperties = PropertiesLoaderUtils.loadAllProperties(CONFIG_PATH); //读取resourse目录下文件
            String property = configProperties.getProperty("config.path");
            if(property !=null && !property.equals("${config.path}")){
                CONFIG_PATH = property;
            }
            FileSystemResource fileSystemResource = new FileSystemResource(CONFIG_PATH);
            properties = PropertiesLoaderUtils.loadProperties(fileSystemResource);
            DOWNLOAD_URL = properties.getProperty("download.url").split(",");
            DOWNLOAD_MODEL = properties.getProperty("download.model");
            DOWNLOAD_PATH = properties.getProperty("download.path") != null ? properties.getProperty("download.path"):DOWNLOAD_PATH ;
        } catch (IOException e) {
            System.out.println( "配置文件读取失败: "+ e.getMessage());
        }
    }


}
